


import * as echarts from 'echarts'
export default {
  methods: {
    GraphCharts_V2Init(v){
      const graphData = {
        nodes: [
          {
            id: '2',
            name: 'MlleBaptistine',
            symbolSize: 6.323809333333333,
            x: -212.76357,
            y: 245.29176,
            value: 9.485714,
            category: 1,
          },
          {
            id: '11',
            name: 'Valjean',
            symbolSize: 20,
            x: -87.93029,
            y: -6.8120565,
            value: 10,
            category: 1,
          },
          {
            id: '12',
            name: 'Marguerite',
            symbolSize: 4.495239333333333,
            x: -339.77908,
            y: -184.69139,
            value: 6.742859,
            category: 1,
          },
          {
            id: '14',
            name: 'Isabeau',
            symbolSize: 2.6666666666666665,
            x: -158.05168,
            y: 201.99768,
            value: 4,
            category: 1,
          },
          {
            id: '15',
            name: 'Gervais',
            symbolSize: 2.6666666666666665,
            x: -127.701546,
            y: 242.55057,
            value: 4,
            category: 1,
          },
          {
            id: '17',
            name: 'Listolier',
            symbolSize: 13.638097333333334,
            x: -516.55884,
            y: -393.98975,
            value: 20.457146,
            category: 2,
          },

          {
            id: '19',
            name: 'Blacheville',
            symbolSize: 13.638097333333334,
            x: -515.1624,
            y: -456.9891,
            value: 20.457146,
            category: 2,
          },
          {
            id: '20',
            name: 'Favourite',
            symbolSize: 13.638097333333334,
            x: -408.12122,
            y: -464.5048,
            value: 20.457146,
            category: 2,
          },
          {
            id: '22',
            name: 'Zephine',
            symbolSize: 13.638097333333334,
            x: -459.1107,
            y: -362.5133,
            value: 20.457146,
            category: 2,
          },
          {
            id: '23',
            name: 'Fantine',
            symbolSize: 28.266666666666666,
            x: -313.42786,
            y: -289.44803,
            value: 42.4,
            category: 2,
          },
          {
            id: '26',
            name: 'Cosette',
            symbolSize: 20.95238266666667,
            x: 78.64646,
            y: -31.512747,
            value: 31.428574,
            category: 6,
          },
          {
            id: '27',
            name: 'Javert',
            symbolSize: 31.923806666666668,
            x: -81.46074,
            y: -204.20204,
            value: 47.88571,
            category: 7,
          },
          {
            id: '29',
            name: 'Bamatabois',
            symbolSize: 15.466666666666667,
            x: -585.6842,
            y: -20.206686,
            value: 23.2,
            category: 3,
          },
          {
            id: '31',
            name: 'Simplice',
            symbolSize: 8.152382000000001,
            x: -281.4253,
            y: -158.45137,
            value: 12.228573,
            category: 2,
          },
          {
            id: '32',
            name: 'Scaufflaire',
            symbolSize: 2.6666666666666665,
            x: -122.41348,
            y: 210.37503,
            value: 4,
            category: 1,
          },
          {
            id: '34',
            name: 'Judge',
            symbolSize: 11.809524666666666,
            x: -387.84915,
            y: 58.7059,
            value: 17.714287,
            category: 3,
          },
          {
            id: '35',
            name: 'Champmathieu',
            symbolSize: 11.809524666666666,
            x: -338.2307,
            y: 87.48405,
            value: 17.714287,
            category: 3,
          },
          {
            id: '36',
            name: 'Brevet',
            symbolSize: 11.809524666666666,
            x: -453.26874,
            y: 58.94648,
            value: 17.714287,
            category: 3,
          },
          {
            id: '37',
            name: 'Chenildieu',
            symbolSize: 11.809524666666666,
            x: -386.44904,
            y: 140.05937,
            value: 17.714287,
            category: 3,
          },
          {
            id: '38',
            name: 'Cochepaille',
            symbolSize: 11.809524666666666,
            x: -646.7876,
            y: 123.38005,
            value: 17.714287,
            category: 3,
          },
          {
            id: '39',
            name: 'Pontmercy',
            symbolSize: 6.323809333333333,
            x: 336.49738,
            y: -269.55914,
            value: 9.485714,
            category: 6,
          },
          {
            id: '43',
            name: 'Woman2',
            symbolSize: 6.323809333333333,
            x: -187.00418,
            y: -145.02663,
            value: 9.485714,
            category: 6,
          },
          {
            id: '46',
            name: 'Jondrette',
            symbolSize: 2.6666666666666665,
            x: 550.3201,
            y: 522.4031,
            value: 4,
            category: 5,
          },
          {
            id: '47',
            name: 'MmeBurgon',
            symbolSize: 4.495239333333333,
            x: 488.13535,
            y: 356.8573,
            value: 6.742859,
            category: 5,
          },
          {
            id: '49',
            name: 'Gillenormand',
            symbolSize: 13.638097333333334,
            x: 126.4831,
            y: 68.10622,
            value: 20.457146,
            category: 6,
          },
          {
            id: '51',
            name: 'MlleGillenormand',
            symbolSize: 13.638097333333334,
            x: 162.63559,
            y: 417.6565,
            value: 20.457146,
            category: 6,
          },
          {
            id: '52',
            name: 'MmePontmercy',
            symbolSize: 4.495239333333333,
            x: 353.66415,
            y: -205.89165,
            value: 6.742859,
            category: 6,
          },
          {
            id: '53',
            name: 'MlleVaubois',
            symbolSize: 2.6666666666666665,
            x: 165.43939,
            y: 339.7736,
            value: 4,
            category: 6,
          },
          {
            id: '54',
            name: 'LtGillenormand',
            symbolSize: 8.152382000000001,
            x: 137.69348,
            y: 196.1069,
            value: 12.228573,
            category: 6,
          },
          {
            id: '55',
            name: 'Marius',
            symbolSize: 20,
            x: 606.44687,
            y: -13.805411,
            value: 53.37143,
            category: 6,
          },
          {
            id: '56',
            name: 'BaronessT',
            symbolSize: 4.495239333333333,
            x: 194.82993,
            y: 224.78036,
            value: 6.742859,
            category: 6,
          },
          {
            id: '68',
            name: 'Gueulemer',
            symbolSize: 19.12381,
            x: 78.4799,
            y: -347.15146,
            value: 28.685715,
            category: 7,
          },
          {
            id: '69',
            name: 'Babet',
            symbolSize: 19.12381,
            x: 150.35959,
            y: -298.50797,
            value: 28.685715,
            category: 7,
          },
          {
            id: '72',
            name: 'Toussaint',
            symbolSize: 6.323809333333333,
            x: 40.942253,
            y: 113.78272,
            value: 9.485714,
            category: 1,
          },
        ],
        links: [
          {
            source: '3',
            target: '2',
          },
          {
            source: '11',
            target: '2',
          },
          {
            source: '12',
            target: '11',
          },
          {
            source: '15',
            target: '11',
          },
          {
            source: '20',
            target: '19',
          },
          {
            source: '22',
            target: '20',
          },
          {
            source: '23',
            target: '11',
          },
          {
            source: '23',
            target: '19',
          },
          {
            source: '26',
            target: '11',
          },
          {
            source: '28',
            target: '27',
          },
          {
            source: '29',
            target: '11',
          },
          {
            source: '29',
            target: '23',
          },
          {
            source: '30',
            target: '23',
          },
          {
            source: '31',
            target: '11',
          },
          {
            source: '31',
            target: '23',
          },
          {
            source: '31',
            target: '30',
          },
          {
            source: '32',
            target: '11',
          },
          {
            source: '34',
            target: '29',
          },
          {
            source: '35',
            target: '11',
          },
          {
            source: '35',
            target: '29',
          },
          {
            source: '36',
            target: '11',
          },
          {
            source: '36',
            target: '29',
          },
          {
            source: '37',
            target: '11',
          },
          {
            source: '37',
            target: '29',
          },
          {
            source: '37',
            target: '34',
          },
          {
            source: '38',
            target: '29',
          },
          {
            source: '42',
            target: '41',
          },
          {
            source: '43',
            target: '11',
          },
          {
            source: '43',
            target: '26',
          },
          {
            source: '47',
            target: '46',
          },
          {
            source: '51',
            target: '11',
          },
          {
            source: '51',
            target: '26',
          },
          {
            source: '52',
            target: '39',
          },
          {
            source: '53',
            target: '51',
          },
          {
            source: '54',
            target: '26',
          },
          {
            source: '54',
            target: '49',
          },
          {
            source: '54',
            target: '51',
          },
          {
            source: '55',
            target: '11',
          },
          {
            source: '55',
            target: '26',
          },
          {
            source: '55',
            target: '39',
          },
          {
            source: '55',
            target: '54',
          },
          {
            source: '56',
            target: '49',
          },
          {
            source: '56',
            target: '55',
          },
          {
            source: '68',
            target: '11',
          },
          {
            source: '68',
            target: '41',
          },
          {
            source: '68',
            target: '48',
          },
          {
            source: '69',
            target: '41',
          },
          {
            source: '69',
            target: '48',
          },
          {
            source: '69',
            target: '68',
          },
          {
            source: '72',
            target: '11',
          },
          {
            source: '72',
            target: '26',
          },
        ],
      }

      let echartEle=  this.$refs[v];
      let myChart = echarts.init(echartEle);

      const {
        dataSourceType,options,staticData
      } = this.controlProperties[v]

      if (dataSourceType === 'static' && Object.keys(staticData).length) {
        options.series = options.series.map((item, index) => {
          return { ...item, ...item.basicConfig, data: staticData.nodes, links: staticData.links }
        })
      } else {
        options.series = options.series.map((item, index) => {
          return { ...item, ...item.basicConfig, data: graphData.nodes, links: graphData.links }
        })
      }
      options && myChart.setOption(options);
     },
     GraphCharts_V2SetOption(v){
        const { options, flowResult, dynamicData:{
          nodes= [], // 节点数据源
          id= [], // 节点唯一值
          name= [], // 节点名称
          value= [], // 节点值
          x= [], // 节点X值
          y= [], // 节点Y值
          category= [], // 节点类型
          links= [], // 连线数据源
          source= [], // 起点
          target= [], // 终点
        }} = this.controlProperties[v]
        let { series } = options
        // series
        series = series.map((item) => {
          item.data = nodes.length?flowResult[nodes[nodes.length-1].dataKey].map(node=>{
            return {
              id:id.length?node[id[id.length-1].dataKey]:undefined,
              name:name.length?node[name[name.length-1].dataKey]:undefined,
              value:value.length?node[value[value.length-1].dataKey]:undefined,
              x:x.length?node[x[x.length-1].dataKey]:undefined,
              y:y.length?node[y[y.length-1].dataKey]:undefined,
              category:category.length?node[category[category.length-1].dataKey]:undefined
            }
          }):[]
          item.links = links.length?flowResult[links[links.length-1].dataKey].map(link=>{
            return {
              source:source.length?link[source[source.length-1].dataKey]:undefined,
              target:target.length?link[target[target.length-1].dataKey]:undefined
            }
          }):[]
        })
        let echartEle = this.$refs[v];
        let myChart = echarts.init(echartEle);
        options && myChart.setOption(options);
     }
   }
  }
